package com.java2007.hotel.filters;

import com.java2007.hotel.pojo.Admin;
import com.java2007.hotel.pojo.User;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author csl
 * @version V1.0
 * @date 2021/01/12
 **/
public class ServiceFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;

        Admin admin = (Admin) httpServletRequest.getSession().getAttribute("admin");
        if (null == admin){
            httpServletResponse.sendRedirect(httpServletRequest.getContextPath()+"/index.jsp");
            return;
        }
        filterChain.doFilter(servletRequest,servletResponse);
    }
}
